package com.linoer.cloud.alo.storageservice.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linoer.cloud.alo.common.domain.ObjectResponse;
import com.linoer.cloud.alo.common.domain.dto.StorageDTO;
import com.linoer.cloud.alo.common.domain.enums.ResponseStatus;
import com.linoer.cloud.alo.storageservice.domain.Storage;
import com.linoer.cloud.alo.storageservice.mapper.StorageMapper;
import org.springframework.stereotype.Service;

/**
 * @Classname StorageServiceImp
 * @Description TODO
 * @Date 2021/6/23 9:45 上午
 * @Created by muhenglv
 */
@Service
public class StorageServiceImp extends ServiceImpl<StorageMapper, Storage> implements StorageService {

    @Override
    public ObjectResponse deduct(StorageDTO storageDTO) {
        ObjectResponse<StorageDTO> response = new ObjectResponse<>();
        int result = this.baseMapper.decreaseStorage(storageDTO.getCommodityCode(), storageDTO.getCount());
        if (result < 0){
            response.setStatus(ResponseStatus.FAIL.getCode());
            response.setMessage(ResponseStatus.FAIL.getMessage());
        }else {
            response.setStatus(ResponseStatus.SUCCESS.getCode());
            response.setMessage(ResponseStatus.SUCCESS.getMessage());
        }
        return response;
    }
}
